<?php
/**
 * 会员
 */
$up_url="../";
include (dirname(__FILE__)."/session.inc.php");//全局变量

//页面属于
$mod=trim(empty($_REQUEST['mod'])?"list":$_REQUEST['mod']);
$smarty->assign("mod",$mod);
$link_url="";
$tb_users="`".$tbprefix."users`";
/*分页数*/
$pagesize =15;
$page =empty($_REQUEST['page'])||($_REQUEST['page']<0)?"1":trim($_REQUEST['page']);
switch ($mod){
	
	//是否显示
	case "ishow":
		/*更新是否显示*/
		@$back_url=$_SESSION['act_url']?$_SESSION['act_url']:"?mod=list";
		if($adminPower<1){
			$uid=empty($_GET['uid'])?0:$_GET['uid'];
			$user_total=$db->get_one("SELECT COUNT(`uid`) AS `total` FROM `{$tbprefix}user` WHERE `uid`='$uid' AND `is_valid`='1' AND 1");
			switch ($user_total['total']){
				case 0:
					//管理员权限
					$fun->msg("无效会员,正在跳转...",$back_url,1);
					break;
				default:
					$ishow=isset($_GET['ishowId'])?$_GET['ishowId']:($fun->msg("操作失败,正在跳转...",$back_url,1));
					$db->query("UPDATE `{$tbprefix}user` SET `status`='".$ishow."' WHERE `uid`='".$uid."' AND 1");
					echo "<script>window.location.href='$back_url';</script>";
					break;
			}
		}else{
			$fun->msg("权限不足",$back_url,1);//错误跳转到新的页面
		}
		break;
	
		//信息列表
	default:

		$condition="";

		$keyword=trim(empty($_GET['keyword'])?"":$fun->checkInput($_GET['keyword']));
		$mobile=trim(empty($_GET['mobile'])?"":$fun->checkInput($_GET['mobile']));
		$status=trim(empty($_GET['status'])?"0":$_GET['status']);
		$t1=trim(empty($_GET['t1'])?"":$_GET['t1']);
		$t2=trim(empty($_GET['t2'])?"":$_GET['t2']);
		
		if($keyword){
			$keywords = str_replace(" ","%",trim(urldecode($keyword)));
			$condition.="((`uname` LIKE '%".$keywords."%')OR(`realname` LIKE '%".$keywords."%')OR(`ncname` LIKE '%".$keywords."%')) AND ";
		}
		$smarty->assign("keyword",$fun->showInput($keyword, ENT_QUOTES, "UTF-8" ));

		if($mobile){
			$mobiles =  str_replace(" ","%",trim(urldecode($mobile)));
			$condition.="((`mobile` LIKE '%".$mobiles."%')) AND ";
		}
		$smarty->assign("mobile",$fun->showInput($mobile, ENT_QUOTES, "UTF-8" ));
		
		if($t1){
			$ts1=strtotime($t1);
			$condition.="(`addtime`>'".$ts1."') AND ";
		}
		$smarty->assign("t1",$t1);
		if($t2){
			$ts2=strtotime($t2." 23:59:59");
			$condition.="(`addtime`<'".$ts2."') AND ";
		}
		$smarty->assign("t2",$t2);

		if($status>0){
			$is_status = ($status-1>0)?1:0;
			$condition.="(`status`='".$is_status."') AND ";
		}
		$smarty->assign("status",$status);
		
		$fpage = $fun->setPageUri();//该页面;

		$mer_sql="SELECT `uid`, `status`, `uname`, `realname`, `ncname`,`sex`, `mobile`,
		`tel`, `email`, `birthday`,`addtime`, `lastlogintime`,`logintime`,`qq`, `is_valid` 
		FROM `{$tbprefix}user` WHERE {$condition} `is_valid`='1' AND 1 ORDER BY `addtime` DESC";

		/*--分页开始--*/
		$numpage = $db->pagedeal($mer_sql, $pagesize);//调用分页处理函数

		//SQL LIMIT起始
		$startloc=(($page-1)*$pagesize<0)?0:($page-1)*$pagesize;

		$merValue=$db->get_all($mer_sql." LIMIT $startloc,$pagesize");
		
		$i=0;											//定义序号初始为0
		$user_arr=array();
		foreach ($merValue as $key=>$value){
			$user_arr[$key]=$value;
			//序号
			$i++;$pageid=(($page-1)*$pagesize)+$i;
			//==查询描红加粗==//
			//时间
			$addtimeDate=!empty($user_arr[$key]['addtime'])?date("Y-m-d H:i:s",$user_arr[$key]['addtime']):"0000-00-00 00:00:00";
			if($t1 || $t2){
				$addtimeDate=str_ireplace($addtimeDate,"<span class=\"xinghao\">".$addtimeDate."</span>",$addtimeDate);
			}
			//==查询描红加粗==//
			$user_arr[$key]['pageid']=$pageid;
			$user_arr[$key]['newtitle']=!empty($value['uname'])?$fun->showInput($value['uname']):"";
			$user_arr[$key]['realname']=!empty($value['realname'])?$fun->showInput($value['realname']):"";
			$user_arr[$key]['addtime']=$addtimeDate;
		}

		$smarty->assign("user_arr",$user_arr);			

		$act_url=$_SESSION['act_url']=$fun->GetCurUrl(1);//获取URL的路径存入session
		//----------------------分页相关的模板变量替换-------------------------//
		$smarty->assign("recordcount", $recordcount); 	//总记录数
		$smarty->assign("pagecount", $pagecount);  		//总页数
		$smarty->assign("prepage", $page - 1);     		//上一页
		$smarty->assign("nexpage", $page + 1);     		//下一页
		$smarty->assign("numpage", $numpage);    		//数字分页
		$smarty->assign("page", $page);			//当前页
		$smarty->assign("fpage", $fpage); 		//要分页的网页
		break;
}


$smarty->assign("title",$cfg['sysName']);
$smarty->display("user.tpl");
?>